<?php
$this->title = "A-PMS项目管理系统-修改协同";
$this->registerCssFile('/css/list/timePicker/jquery-ui-timepicker-addon.css');
$this->registerCssFile('/css/list/timePicker/jquery-ui-1.11.4.css');
$this->registerCssFile('/css/officeHall/uploadAssetPackage/initiateSynergy.css');
$this->registerCssFile('/css/adminLTE/select2.min.css',['depends'=>'\yii\bootstrap\BootstrapAsset']);
$this->registerCssFile('/css/adminLTE/font-awesome.min.css',['depends'=>'\yii\bootstrap\BootstrapAsset']);
$this->registerCssFile('/css/adminLTE/daterangepicker.css',['depends'=>'\yii\bootstrap\BootstrapAsset']);


$this->registerJsFile('/js/officeHall/uploadAssetPackage/initiateSynergy.js');
$this->registerJsFile('/css/list/timePicker/jquery-ui-1.11.4.js');
$this->registerJsFile('/css/list/timePicker/zh-CN.js');
$this->registerJsFile('/js/adminLTE/bootstrap.min.js');
$this->registerJsFile('/js/adminLTE/select2.full.min.js');
$this->registerJsFile('/js/adminLTE/moment.min.js');
$this->registerJsFile('/js/adminLTE/daterangepicker.js');
$this->registerJsFile('/css/list/timePicker/jquery-ui-timepicker-addon.js');
$this->registerJsFile('/css/list/timePicker/jquery-ui-timepicker-zh-CN.js');
?>
<div class="container containerShadow">
        <div class="row">
            <div class="topimg">
                <div class="left pull-left">
                    <span>团队成员 </span>
                </div>
                <!--<div class="pull-right">
                <a href="###">
                <img src="image/projectDetails/edit.png" >
                </a>
            </div>-->
            </div>
            <form action="" method="" ; class="tuanDuiEdit">
                <div class="clearfix">
                    <label for="" class="pull-left">项目总监</label>
                    <select class="form-control select212" data-placeholder="Select a State"
                            style="width: 100%;">
                        <?php
                            if (!empty($userChief)){
                                foreach ($userChief as $k => $v) {
                                    $username = $v['realname'];
                                    $id       = $v['id'];
                                    echo "<option value='".$id."'>".$username."</option>";
                                }
                            }
                        ?>
                    </select>
                </div>
                <div class="clearfix">
                    <label for="" class="pull-left">项目经理</label>
                    <select class="form-control select3"  data-placeholder="Select a State"
                            style="width: 100%;">
                        <?php
                        if (!empty($user)&& is_array($user)){
                            foreach ($user as $k => $v) {
                                $username = $v['realname'];
                                $id       = $v['id'];
                                echo "<option value='".$id."'>".$username."</option>";
                            }
                        }
                        ?>
                    </select>
                </div>
                <div class="clearfix">
                    <label for="" class="pull-left">团队成员</label>
                    <select class="form-control select4" multiple="multiple" data-placeholder="Select a State"
                            style="width: 100%;">
                        <?php
                        if (!empty($user) && is_array($user)){
                            foreach ($user as $k => $v) {
                                $user = $v['realname'];
                                $id       = $v['id'];
                                echo "<option value='".$id."'>".$user."</option>";
                            }
                        }
                        ?>
                    </select>
                </div>

                <div class="clearfix">
                    <label for="" class="pull-left">其他说明</label>
                    <textarea name="" rows="" cols="" class="textarea-edit" id="content"><?= !empty($team['explain'])?$team['explain']:''?></textarea>
                    <!--<input type="text" class="pull-right" placeholder="扬州加盟商赵亚青协助尽调" />-->
                </div>
                <div class="cancelInConfirm">
                    <input id="ajaxTeam" class="cancelInConfirmActive" type="button" value="保存" />
                    <input id='cancelTeam' type="button" value="取消" />
                </div>

            </form>

        </div>
    </div>

    	<!-- textarea 高度设置对比div -->

	<div style="max-height: 1px; overflow: hidden;">

		<div id="d1" style="visibility:hidden;min-height: 80px;"></div>

	</div>

<script>
    $(function () {
	     // textarea 高度展示问题
	    $(".textarea-edit").focus(function(){
	     	textareaHeight($(this));
	    });
	     $(".textarea-edit").keyup(function(){
	     	textareaHeight($(this));
	    });
	     function textareaHeight(th){
	    	 var val = th.val();
		      $("#d1").width($(th).width())
		      $("#d1").html("<pre>" +val+" "+"</pre>");
		      var h = $("#d1").height() ;
		      th.height(h);
	    }
        //初始化值
        var chiefStr = JSON.parse('<?= json_encode($teamZJ)?>');
        var chiefId = $.grep( '<?=  $team['manager'] ?>'.split(','), function(n) {return $.trim(n).length > 0;});
        var leaderStr =  JSON.parse('<?= json_encode($teamFZR)?>');
        var leaderId =  $.grep( '<?=  $team['owner'] ?>'.split(','), function(n) {return $.trim(n).length > 0;});
        var userStr = JSON.parse('<?= json_encode($teamXZR)?>');
        var userId = $.grep( '<?=  $team['partner'] ?>'.split(','), function(n) {return $.trim(n).length > 0;});
        //Initialize Select2 Elements
        $('.select212').select2({
            data: chiefStr,
        });
        $('.select212').select2('val',chiefId);

        $('.select3').select2({
            data: leaderStr,
        });
        $('.select3').select2('val',chiefId);
        $('.select4').select2({
            data: userStr,
        }).val(userId).trigger('change');
            $("#ajaxTeam").click(function () {
            var dataChief =$(".select212").val();
            var dataLeader=$(".select3").val();
            var dataUser  =$(".select4").val();
            var content = $("#content").val();
            $.post('/project/ajax-save-team-project',{'dataChief':dataChief,'dataLeader':dataLeader,'dataUser':dataUser,'content':content,'project_id':project_id},function (res) {
                var JSONData = JSON.parse(res)
                if (JSONData.code == 200){
                    layer.msg(JSONData.message);
                    teamW();
                }else{
                    layer.msg(JSONData.message);
                }
            })
        })
        //-----------------渲染无编辑页面--------------------
        function teamW() {
            $.get('/project/get-base-data',{'project_id':project_id,'postion':14},function (res) {
                $(".tuanDuiChengYuanW").children().remove();
                $(".tuanDuiChengYuanW").html(res);
                $(".tuanDuiChengYuanEdit").hide();
                $(".tuanDuiChengYuanW").show();
            })
        }
        //-----取消保存按钮
        $("#cancelTeam").click(function () {
            $.post('/project/ajax-un-lock',{'postion':14,'project_id':project_id},function (res) {
                var JSONData = JSON.parse(res)
                if (JSONData.code == 200){
                    layer.msg(JSONData.message);
                }else{
                    layer.msg(JSONData.message);
                }
            })
            $(".tuanDuiChengYuanEdit").hide();
            $(".tuanDuiChengYuanW").show();
        })
    })
</script>